package com.ruoyi.interview.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.interview.domain.TbPost;
import com.ruoyi.interview.service.ITbPostService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 岗位Controller
 * 
 * @author ruoyi
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/post")
public class TbPostController extends BaseController
{
    @Autowired
    private ITbPostService tbPostService;

    /**
     * 查询岗位列表
     */
    @RequiresPermissions("interview:post:list")
    @GetMapping("/list")
    public TableDataInfo list(TbPost tbPost)
    {
        startPage();
        List<TbPost> list = tbPostService.selectTbPostList(tbPost);
        return getDataTable(list);
    }

    /**
     * 导出岗位列表
     */
    @RequiresPermissions("interview:post:export")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPost tbPost)
    {
        List<TbPost> list = tbPostService.selectTbPostList(tbPost);
        ExcelUtil<TbPost> util = new ExcelUtil<TbPost>(TbPost.class);
        util.exportExcel(response, list, "岗位数据");
    }

    /**
     * 获取岗位详细信息
     */
    @RequiresPermissions("interview:post:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbPostService.selectTbPostById(id));
    }

    /**
     * 新增岗位
     */
    @RequiresPermissions("interview:post:add")
    @Log(title = "岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPost tbPost)
    {
        return toAjax(tbPostService.insertTbPost(tbPost));
    }

    /**
     * 修改岗位
     */
    @RequiresPermissions("interview:post:edit")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPost tbPost)
    {
        return toAjax(tbPostService.updateTbPost(tbPost));
    }

    /**
     * 删除岗位
     */
    @RequiresPermissions("interview:post:remove")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPostService.deleteTbPostByIds(ids));
    }
}
